/**
 * @file Family Tree.cpp
 * @author GalaktiK (jacobliu001@domain.com)
 * @version 1.0
 * @date 2021-06-02
 *
 * @copyright Copyright (c) 2021
 * @todo add comments
 */
#include <bits/stdc++.h>
using namespace std;
int n;
int cnt = 0;
int CASE = 0;
int m;
map<string,int> mapp;
struct ind {
    set<int> ch;
    set<int> pa;
    int spouse;
};
ind p[114];
bool operator == (const ind &a, const ind &b) {
    if (a.ch == b.ch && a.pa == b.pa) {
        return true;
    }
    return false;
}

bool isSpouse(ind &x, ind &y) {
    for (int i = 1; i <= cnt; i++) {
        if (x.ch.find(i) != x.ch.end() && y.ch.find(i) != y.ch.end()) {
            return true;
        }
    }
    return false;
}
bool isParent(ind &x, ind &y) {
    for (set<int>::iterator i=y.ch.begin(); i != y.ch.end(); i++) {
        if (p[(*i)] == x) {
            return true;
        }
    }
    for (set<int>::iterator i=x.pa.begin(); i != x.pa.end(); i++) {
        if (p[(*i)] == y) {
            return true;
        }
    }
    return false;
}
bool isChild(ind &x, ind &y) {
    return isParent(y, x);
}
bool isGrandParent(ind &x, ind &y) {
    for (int i = 1; i <= cnt; i++) {
        if (isParent(x, p[i])) {
            if (isParent(p[i], y)) {
                return true;
            }
        }
    }
    return false;
}
bool isGrandChild(ind &x, ind &y) {
    return isGrandParent(y, x);
}
bool isGGP(ind &x, ind &y) {
    for (int i = 1; i <= cnt; i++) {
        if (isParent(x, p[i]) && isGrandParent(p[i], y)) {
            return true;
        }
        if (isGrandParent(x, p[i]) && isParent(p[i], y)) {
            return true;
        }
    }
    return false;
}
bool isGGC(ind &x, ind &y) {
    return isGGP(y, x);
}
bool isSibling(ind &x, ind &y) {
    for (int i = 1; i <= cnt; i++) {
        if (isParent(x, p[i]) && isParent(y, p[i])) {
            return true;
        }
    }
    return false;
}
bool isCousin(ind &x, ind &y) {
    for (int i = 1; i <= cnt; i++) {
        if (!isParent(x, p[i])) continue;
        for (int j = 1; j <= cnt; j++) {
            if (!isParent(y, p[j])) continue;
            if (isSibling(p[i], p[j])) {
                return true;
            }
        }
    }
    return false;
}
bool isSecCousin(ind &x, ind &y) {
    for (auto i: x.pa) {
        for (auto j: y.pa) {
            if (isCousin(p[i], p[j])) {
                return true;
            }
        }
    }
    return false;
}
bool isPibling(ind &x, ind &y) {
    for (int i = 1; i <= cnt; i++) {
        if (isParent(x, p[i])) {
            if (isSibling(p[i], y)) {
                return true;
            }
        }
    }
    return false;
}
bool isGrandPib(ind &x, ind &y) {
    /*for (auto i: x.pa) {
        for (auto j: p[i].pa) {
            if (isSibling(p[j], y)) {
                return true;
            }
        }
    }*/
    for (int i = 1; i <= cnt; i++) {
        if (isGrandParent(x, p[i])) {
            if (isSibling(p[i], y)) {
                return true;
            }
        }
    }
    return false;
}
bool isNib(ind &x, ind &y) {
    return isPibling(y, x);
}
bool isGrandNib(ind &x, ind &y) {
    return isGrandPib(y, x);
}
void solve() {
    mapp.clear();
    cin >> n;
    cnt = 0;
    for (int i = 0; i < n; i++) {
        string s1, s2;
        cin >> s1 >> s2;
        if (mapp[s1] == 0) {
            mapp[s1] = ++cnt;
            p[cnt] = ind();
        }
        if (mapp[s2] == 0) {
            mapp[s2] = ++cnt;
            p[cnt] = ind();
        }
        int c1, c2;
        c1 = mapp[s1]; c2 = mapp[s2];
        p[c2].pa.insert(c1);
        p[c1].ch.insert(c2);
    }
    for (int i = 1; i <= cnt; i++) {
        for (int j = i + 1; j <= cnt; j++) {
            if (isSpouse(p[i], p[j])) {
                p[i].spouse=j;p[j].spouse=i;
                /*
                for (auto x: p[i].ch) { p[j].ch.insert(x); }
                for (auto x: p[j].ch) { p[i].ch.insert(x); }
                for (auto x: p[i].pa) { p[j].pa.insert(x); }
                for (auto x: p[j].pa) { p[j].pa.insert(x); }*/
                p[i].ch.merge(p[j].ch);
                p[j].ch.merge(p[i].ch);
                p[i].pa.merge(p[j].pa);
                p[j].pa.merge(p[i].pa);

            }
        }
    }

    // cout << "SORTED" << endl;
    cin >> m;
    for (int i = 0; i < m; i++) {
        string s1, s2;
        cin >> s1 >> s2;
        int c1, c2;
        c1 = mapp[s1]; c2 = mapp[s2];
        ind &a = p[c1];
        ind &b = p[c2];
        if (isSpouse(a, b)) {
            cout << (++CASE) << ". " << "spouse" << endl; continue;
        } else if (isParent(a, b)) {
            cout << (++CASE) << ". " << "parent" << endl; continue;
        } else if (isChild(a, b)) {
            cout << (++CASE) << ". " << "child" << endl; continue;
        } else if (isGrandChild(a, b)) {
            cout << (++CASE) << ". " << "grandchild" << endl; continue;
        } else if (isGrandParent(a, b)) {
            cout << (++CASE) << ". " << "grandparent" << endl; continue;
        } else if (isGGC(a, b)) {
            cout << (++CASE) << ". " << "great-grandchild" << endl; continue;
        } else if (isGGP(a, b)) {
            cout << (++CASE) << ". " << "great-grandparent" << endl; continue;
        } else if (isSibling(a, b)) {
            cout << (++CASE) << ". " << "sibling" << endl; continue;
        } else if (isCousin(a, b)) {
            cout << (++CASE) << ". " << "cousin" << endl; continue;
        } else if (isSecCousin(a, b)) {
            cout << (++CASE) << ". " << "second cousin" << endl; continue;
        } else if (isPibling(a, b)) {
            cout << (++CASE) << ". " << "pibling" << endl; continue;
        } else if (isGrandPib(a, b)) {
            cout << (++CASE) << ". " << "grandpibling" << endl; continue;
        } else if (isNib(a, b)) {
            cout << (++CASE) << ". " << "nibling" << endl; continue;
        } else if (isGrandNib(a, b)) {
            cout << (++CASE) << ". " << "grandnibling" << endl; continue;
        } else {
            cout << "FUCK" << endl; CASE++; continue;
        }

    }
}


int main() {
    while (CASE != 10) {
        solve();
    }
    return 0;
}
